package improve;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-22
 * Time: 16:52
 */

public class Client {
    public static void main(String[] args) {

        Sheep sheep = new Sheep("tom", 1, "白色");
        //克隆的时候就将属性赋值了

        //浅拷贝
        sheep.friend = new Sheep("jack",2,"黑色");
        System.out.println(sheep.friend.hashCode());

        //非常的方便 羊的信息发生变化 不会影响到客户端的使用
        Sheep sheep1 = (Sheep) sheep.clone(); //克隆
        Sheep sheep2 = (Sheep) sheep.clone(); //克隆
        Sheep sheep3 = (Sheep) sheep.clone(); //克隆
        Sheep sheep4 = (Sheep) sheep.clone(); //克隆
        Sheep sheep5 = (Sheep) sheep.clone(); //克隆

        System.out.println(sheep1 + ""  + sheep1.friend.hashCode()); //验证克隆之后的羊的朋友是谁
        System.out.println(sheep2 + ""  + sheep2.friend.hashCode());
        System.out.println(sheep3 + ""  + sheep3.friend.hashCode());
        System.out.println(sheep4 + ""  + sheep4.friend.hashCode());
        System.out.println(sheep5 + ""  + sheep5.friend.hashCode());
        //460141958
        //Sheep{name='tom', age=1, color='白色'}460141958
        //Sheep{name='tom', age=1, color='白色'}460141958
        //Sheep{name='tom', age=1, color='白色'}460141958
        //Sheep{name='tom', age=1, color='白色'}460141958
        //Sheep{name='tom', age=1, color='白色'}460141958
        //得出的结果是 后面这个对象 hashCode相同 都是执行的了原来的对象 并没有复制新的对象

    }
}
